package com.zm.demo.spring.tx.manager.impl;

import com.zm.demo.spring.tx.manager.UserManager;
import com.zm.demo.spring.tx.po.User;
import com.zm.demo.spring.tx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
public class UserManagerImpl implements UserManager {
    @Autowired
    UserService userService;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int insertUser(User entity) {
        try {
            userService.insertUser(entity);
            userService.updateBatch(Arrays.asList(entity));
        } catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }
}
